package org.example;

/**
 * 两个数字的字符串，进行相加，不能使用Integer.valueOf()方法，输出整数字符串
 */
public class 字符整数相加 {
	public static void main(String[] args) {
		System.out.println(strAdd("62", "54"));
		String s = "abc";
		System.out.println(s.charAt(0) - '0');
	}

	public static StringBuffer strAdd(String a, String b) {
		int aLength = a.length() - 1;
		int bLength = b.length() - 1;
		StringBuffer result = new StringBuffer();
		int temp = 0;
		while (aLength >= 0 || bLength >= 0 || temp != 0) {
			int i = aLength >= 0 ? (a.charAt(aLength--) - '0') : 0;
			int j = bLength >= 0 ? (b.charAt(bLength--) - '0') : 0;
			int x = i + j + temp;
			temp = x / 10;
			int postion = x % 10;
			result.append(postion);
		}
		result.reverse();
		return result;
	}
}
